package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: SetmealController
 * USER: zhang
 * DATE: 2023/5/21
 * DESCRIPTION :
 */
@Slf4j
@RestController("userSetmealController")
@Api(tags = "C端-套餐信息表现层接口")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Resource
    private SetmealService setmealService;


    /**
     * 根据分类id查询套餐信息
     *
     * @param categoryId 类别id
     * @return 套餐List集合
     */
    @GetMapping("/list")
    @Cacheable(cacheNames = "SETMEAL_CACHE",key = "#categoryId")
    public Result<List<Setmeal>> selectSetmealByCategoryId(Long categoryId) {
        List<Setmeal> setmealList = setmealService.getSetmealByCategoryId(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐Id查询包含菜品信息
     * @param id 套餐Id
     * @return 全局通用返回信息Bean(套餐中菜品的基本信息)
     */
    @GetMapping("/dish/{id}")
    @Cacheable(cacheNames = "SETMEAL_CACHE",key = "#id")
    public Result<List<DishItemVO>> selectSetmealDishBySetmealId(@PathVariable Long id) {
        List<DishItemVO> dishItemVOList = setmealService.selectSetmealDishBySetmealId(id);
        return Result.success(dishItemVOList);
    }
}
